package code;

import java.util.LinkedList;

/**
 * 剑指 Offer 09. 用两个栈实现队列
 * 输入：
 * ["CQueue","appendTail","deleteHead","deleteHead"]
 * [[],[3],[],[]]
 * 输出：[null,null,3,-1]
 * 输入：["CQueue","deleteHead","appendTail","appendTail","deleteHead","deleteHead"]
 * [[],[],[5],[2],[],[]]
 * 输出：[null,-1,null,null,5,2]
 *
 *
 * 添加的时候return null，删除的时候return被删除的元素
 */
public class CQueue {
    LinkedList<Integer> A,B;
    public CQueue() {
        A = new LinkedList<>();
        B = new LinkedList<>();
    }

    public void appendTail(int value) {
        A.add(value);
    }

    public int deleteHead() {
        if (B.isEmpty()){
            while (!A.isEmpty()){
                B.add(A.pop());
            }
            return B.pop();
        }else {
            return B.pop();
        }

    }
}
